#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<math.h>
using namespace std;


//方法1
class Solution {
public:
    bool find132pattern(vector<int>& nums) {
        //先把132中的1确定下来了
        vector<int> T;
        T.push_back(nums[0]);
        for(int i = 1;i<nums.size();++i){
            T.push_back(min(T[i-1],nums[i]));
        }
        stack<int> S; //单调栈
        for(int j = nums.size()-1;j>0;--j){
            if(S.empty()){
                S.push(nums[j]);
            }
            else{
                int temp = -1*pow(10,9)-1;
                while(!S.empty()&&S.top()<nums[j]){
                    temp = S.top();
                    S.pop();
                }
                if(temp>T[j-1]){
                    return true;
                }
                S.push(nums[j]);

            }
        }
        return false;

    }
};


int main(){
    Solution S;
    vector<int>  nums = {-1,3,2,0};
    cout<<S.find132pattern(nums)<<endl;
}